/*
    一些公用的动画特效等；
 */
class PublicGameEffectPanel extends eui.Component
{
    private allSendOKCallback: Function = null;
    private sendTotal: number = 0;
    private sentCount: number = 0;

    public playSendCardEffect(sendCardPoint: any, componentCards: eui.Component[], callBack: Function): void
    {
        this.sendTotal = 0;
        this.sentCount = 0;
        this.allSendOKCallback = callBack;
        sendCardPoint = sendCardPoint.localToGlobal();
        for(var idx = 0; idx < componentCards.length; ++idx)
        {
            var waitTime = 0;
            var componentCard: eui.Component = componentCards[idx];
            var imgCard0 = componentCard["card0"];
            var endPoint0 = new egret.Point(imgCard0.x, imgCard0.y);
            var startPoint = imgCard0.globalToLocal(sendCardPoint.x, sendCardPoint.y);
            var cards: Array<any> = [];
            for(var j = 0;; ++j)
            {
                var imgCard = componentCard["card" + j];
                if(imgCard)
                {
                    cards.push(imgCard);
                }
                else break;
            }
            cards = cards.reverse();
            for(var imgCard of cards)
            {
                waitTime += 100;
                var endPoint = new egret.Point(imgCard.x, imgCard.y);
                imgCard.x = startPoint.x;
                imgCard.y = startPoint.y;
                this.sendTotal += 1;
                egret.Tween.get(imgCard).
                wait(waitTime).
                set({visible:true}).
                to({x:endPoint0.x, y:endPoint.y}, 400, egret.Ease.quadInOut).
                wait(300).
                to({x: endPoint.x}, 500, egret.Ease.cubicOut).
                call(this.sendCardOK.bind(this));
            }
        }
    }

    public sendCardOK(): void
    {
        this.sentCount += 1;
        if(this.sentCount == this.sendTotal)
        {
            if(this.allSendOKCallback)
            {
                this.allSendOKCallback();
                this.allSendOKCallback = null;
            }
        }
    }
}